package com.adamfass.jmetest;

import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.MaterialState;

public class AddNodeDuringUpdate extends SimpleGame {

  Spatial spatial;
  
  protected void simpleInitGame() {
  }
  
  protected void simpleUpdate() {
    if (spatial != null) {
      spatial.setLocalScale(new Vector3f(timer.getTimeInSeconds(), 1, 1));
      return;
    }
    spatial = new Sphere("new sphere", 10, 10, 5);
    
    MaterialState materialState = display.getRenderer().createMaterialState();
    materialState.setEnabled(true);
    materialState.setAmbient(ColorRGBA.green);
    spatial.setRenderState(materialState);
    
    spatial.setLocalScale(new Vector3f(1, 2, 1));
    
    rootNode.attachChild(spatial);
    rootNode.updateRenderState();
  }
  
  /**
   * @param args
   */
  public static void main(String[] args) {
    AddNodeDuringUpdate addNodeDuringUpdate = new AddNodeDuringUpdate();
    addNodeDuringUpdate.setDialogBehaviour(
            AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
    addNodeDuringUpdate.start();
  }

}
